/**
 * Copyright 2009 Sergio Bossa
 *
 *    Licensed under the Apache License, Version 2.0 (the "License");
 *    you may not use this file except in compliance with the License.
 *    You may obtain a copy of the License at
 *
 *        http://www.apache.org/licenses/LICENSE-2.0
 *
 *    Unless required by applicable law or agreed to in writing, software
 *    distributed under the License is distributed on an "AS IS" BASIS,
 *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *    See the License for the specific language governing permissions and
 *    limitations under the License.
 */
package com.googlecode.actorom.impl.local;

import com.googlecode.actorom.Actor;
import com.googlecode.actorom.impl.core.AbstractTopology;
import com.googlecode.actorom.impl.core.ThreadingPolicy;
import com.googlecode.actorom.support.ThreadingPolicies;
import net.jcip.annotations.ThreadSafe;

/**
 * {@link com.googlecode.actorom.Topology} implementation to use for local-only, in-memory,
 * actors.<br>
 * A LocalTopology instance is able to:
 * <ul>
 * <li>Locally spawn actors.</li>
 * <li>Access its own local actors by using their {@link LocalAddress}, but not actors spawned
 * by other LocalTopology instances.</li>
 * </ul>
 *
 * @author Sergio Bossa
 */
@ThreadSafe
public class LocalTopology extends AbstractTopology<LocalAddress> {

    public LocalTopology() {
        this(ThreadingPolicies.newGreenThreadingPolicy());
    }

    public LocalTopology(ThreadingPolicy threadingPolicy) {
        super(threadingPolicy);
    }

    public LocalAddress spawnActor(String id, Object handler) {
        LocalAddress address = new LocalAddress(id);
        boolean spawned = doSpawnActor(address, handler);
        if (spawned) {
            return address;
        } else {
            return null;
        }
    }

    public Actor getActor(LocalAddress address) {
        if (address == null) {
            return null;
        } else {
            return doGetActor(address);
        }
    }

    public void shutdown() {
        doShutdown();
    }
}
